<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-inline">
        <input type="text" class="layui-input date" readonly id="start" placeholder="报备时间-起">
    </div>
    <div class="layui-inline">
        <input type="text" class="layui-input date" readonly id="end" placeholder="报备时间-止">
    </div>
    <div class="layui-inline">
        <input type="text" placeholder="司机姓名" class="layui-input" id="driver_name">
    </div>
    <div class="layui-inline">
        <input type="text" required placeholder="司机电话" class="layui-input" id="driver_phone">
    </div>
    <div class="layui-inline">
        <button class="layui-btn" data-type="search">搜索</button>
        <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
    </div>
    <table class="layui-table"
           lay-data="{ height:'auto', url:'{:url('driver_service/tableSpecial')}', page: true, limit: '10', id:'special'}"
           lay-filter="special">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'case_id', width:80, fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'driver_name', width:120}">司机姓名</th>
            <th lay-data="{field:'driver_phone', width:120}">司机号码</th>
            <th lay-data="{field:'case_detail', width:120,}">报备事由</th>
            <th lay-data="{field:'add_time', width:140 }">报备时间</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:160, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
        <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    </script>
    <script type="application/javascript">
        layui.use(['table', 'form', 'laydate', 'layer'], function () {
            var table = layui.table
                , form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate;
            lay('.date').each(function(){
                laydate.render({
                    elem: this
                    ,type: 'date'
                    ,trigger: 'click'
                });
            });

            //监听表格复选框选择
            table.on('checkbox(special)', function (obj) {
                console.log(obj)
            });
            //监听工具条
            table.on('tool(special)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var case_id = data.case_id;
                if (layEvent === 'del') {
                    layer.confirm('确定删除吗?', function (index) {
                        var url = "{:U('specialDel')}";
                        $.post(url, {'case_id': case_id}, function (data) {
                            console.log(data);
                        }, 'json');
                        layer.close(index);
                    });
                }
                else if (layEvent === 'detail') {
                    layer.open({
                        type: 2,
                        title: '特殊情况报备详情',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: '{:url("/admin/driver_service/specialDetail","case_id=")}' + case_id //iframe的url
                    });
                }
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var driver_name = $.trim($('#driver_name').val());
                    var driver_phone = $.trim($('#driver_phone').val());
                    var reset = $('#reset');
                    if (start || end || driver_name || driver_phone) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('special', {
                            url: '/admin/driver_service/specialSearch',
                            where: {
                                start: start,
                                end: end,
                                driver_name: driver_name,
                                driver_phone: driver_phone
                            } //设定异步数据接口的额外参数
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('special', {
                            url: '/admin/driver_service/tableSpecial',where:{}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</block>
